<?php
session_start();
error_reporting(0);
?>
<script language="javascript">

function ventanaSecundaria (URL){ 
   window.open(URL,"Resultado","width=120,height=300") 
} 

</script>

<?php
include ('../Connections/conn.php');
include ('../consultas.php');

require_once("json.php");   
// read data

if(isset($_GET['anarama']))
	{
		$inicio= $_GET['anarama'];
		$aQue = $_GET['palabras'];
		
	}
else
	{
		$inicio= $_GET['inicio'];
		$aQue = $_GET['palabras'];
	}
	
$texto= preg_replace("/\s/","+",$aQue); 	

$aKey = "ABQIAAAAJv7ugKyQCYLoQdj1qWuX1hQZGWqXahEItCS3QxCDZmCYq62T3hTnmRRiB8pVy0Ggi0aT6Pg_-NyFTg";
$cx ="000873780716165794583:vp4notrvo_q";
$aUrl = "http://ajax.googleapis.com/ajax/services/search/web";
//echo $inicio." ".$texto;
?>
<form method="POST" id='form' name='form'>
<table width='100%' align="left">
<?php
$num=0;
for ($i=0;$i<15;$i++)
{
	
	$tmpHTML="";
	$start=$inicio+($i*4);
	//echo $aUrl."?v=1.0&key=".$aKey."&cx=".$cx."&q=".$texto."&start=".$start;
	$data = file_get_contents($aUrl."?v=1.0&key=".$aKey."&cx=".$cx."&q=".$texto."&start=".$start);
	//print_r($data);
	
	
	$json = new Services_JSON;
	$obj = $json->decode($data);
	$results = $obj->responseData->results;
	for ($j=0; $j<sizeof($results); $j++) {
	
	
	
   	 $tmp = $results[$j];
   	 $tmpHTML.= "<tr align='left'><td><span align='center'><input type='checkbox' value='' id='check_".$num."' name='check_".$num."'>
   	 <input type='hidden'  id='url_".$num."' name='url_".$num."' value='".$tmp->url."'>
   	 <input type='hidden'  id='title_".$num."' name='title_".$num."' value='".$tmp->title."'>
   	 <input type='hidden'  id='content_".$num."' name='content_".$num."' value='".$tmp->content."'></span></td>
   	 <td><a href=\"javascript:ventanaSecundaria ('".$tmp->url."');\">".$tmp->title."</a>";
   	 $tmpHTML.= "<br><label class='encabezado'>".$tmp->content."</label><br>";
   	 $tmpHTML.= "<i>".$tmp->url."</i><br><br><br><br></td></tr>";
	 $num++;
	
	
	
	}
	echo $tmpHTML;
	

}


?>
<br>
<br>
</table>
<input type='hidden' name='representante' value='0' id='representante'>
<input type='hidden' name='categoria' value='0' id='categoria'>
<input type='hidden' name='palabras' id='palabras' value='<?=$_GET['palabras']?>'>

</form>
<table align="center">
<tr>
	<td>
	<?php
	
	
	$link=mysql_connect("localhost","root","");
	mysql_select_db("totus");
	$query="SELECT * FROM empresa";
	$consulta=mysql_query($query);
	
	$select="<form id='ayudita' name='ayudita' method='post'>Selecciona Empresa:<br><select id='sel' name='sel' onchange=\"repre();\">
	<option value='0'>Selecciona</option>";
	
	while($row=mysql_fetch_array($consulta))
	{
		$select.="<option value='".$row['id_empresa']."'>".$row['nombre']."</option>";
	}
	$select.="</select></form>";
	
	echo "<div id='total' style='text-align:left'>
   	 	
   	 	<div id='uno' style='text-align:center'>".$select."<br></div>
   	 <div id='dos' style='text-align:center'></div>
   	 <div id='tres' style='text-align:center'></div>
   	 	<div id='errorsito' style='text-align:center; color:red;'></div>
   	 
   	 <div id='individual' style='text-align:center'>
   	 
   	 <form method='post'  action='javascript:verificacion();'>
   	 	

		<input type='submit' value='Agregar como ticket'>		
	</form>
   	 </div>
   	 
   	 
   	 </div>";
	?>
	</td>
</tr>
</table>


